﻿/**************************************************************

* Copyright (C) 2010 iTouch, Inc (http://www.cnblogs.com/Leo_wl)

* All Rights Reserved

* Created by Leo.wl <QQ:114818988>

 

* 版权所有：Microsoft Corporation.

* 作    者：Leo.wl(nmgimust_wl@163.com)

* 创建时间：2010-06-11

 

* 修 改 人：

* 修改内容：

* 修改时间：

**************************************************************/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using LibraryModels;
using Microsoft.ApplicationBlocks.Data;
using GotDotNet.ApplicationBlocks.Data;
using System.Data;
using System.Data.SqlClient;
using LibraryUtility;
using LibraryUtility.Common;
using LibraryUtility.Data;
using LibraryUtility.OralceLib;
using LibraryUtility.Web;


namespace LibraryBLL.BookBLL
{
    /// <summary>
    /// Open Book Info 
    /// </summary>
    public class OpenBookInfoBLL
    {
        private static readonly string conn = LibraryUtility.Common.ConnConfig.ConnString;
        private SqlParameter para; //参数
        public OpenBookInfoBLL() { }

        /// <summary>
        /// 返回图书信息
        /// </summary>
        /// <param name="messages">The messages.</param>
        /// <returns></returns>
        public string GetOpenBookInfoAll(string messages)
        {
            LibraryUtility.Data.JSONHelper jsonHelp = new LibraryUtility.Data.JSONHelper();
            jsonHelp.success = true;
            SqlParameter[] sp ={
                    para = new SqlParameter("@message",messages)
                };
            DataSet ds = SqlHelper.ExecuteDataset(conn,CommandType.StoredProcedure,"GetOpenBookInfoAll",sp);
             foreach (DataRow dr in ds.Tables[0].Rows)
            {
                jsonHelp.AddItem("OpenRoomId", dr["OpenRoomId"].ToString());
                jsonHelp.AddItem("Number", dr["Number"].ToString());
                jsonHelp.AddItem("TypeName", dr["TypeName"].ToString());
                jsonHelp.AddItem("TypePrice", dr["TypePrice"].ToString());
                jsonHelp.AddItem("OpenTime", dr["OpenTime"].ToString());
                jsonHelp.AddItem("GuestMoney", dr["GuestMoney"].ToString());
                jsonHelp.AddItem("GuestNumber", dr["GuestNumber"].ToString());
                jsonHelp.AddItem("GuestName", dr["GuestName"].ToString());
                jsonHelp.AddItem("Remark", dr["Remark"].ToString());
                jsonHelp.ItemOk();
            }
            string str = jsonHelp.ToString();
            return str;
                 
        }

        /// <summary>
        /// 借书操作
        /// </summary>
        /// <param name="objBook">The obj book.</param>
        /// <returns></returns>
        public int OpenBook(TabBorrowBooks objBook)
        {
            int count = 0;
            try
            {
                SqlParameter[] sp = {
                                        para = new SqlParameter("@BookID",objBook.BookID),
                                        para = new SqlParameter("@UserID",objBook.UserID),
                                        para = new SqlParameter("@StartTime",System.DateTime.Now),
                                        para = new SqlParameter("@EndTime",System.DateTime.Now.AddDays(30)),
                                        para = new SqlParameter("@Remark",objBook.Remark)
                                  };
                count = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "OpenBook", sp);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return count;
        }



        /// <summary>
        /// 还书操作
        /// </summary>
        /// <param name="Number"></param>
        /// <returns></returns>
        public int CloseBook(string Number)
        {
            int count = 0;
            try
            {
                SqlParameter[] sp = {
                    para = new SqlParameter("@BookNumber",Number)
                                    };
                count = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "CloseBook", sp);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return count;
        }
    }
}
